package co.baiku.boot.component.core.service;

import co.baiku.boot.component.core.event.OrmEventListener;
import co.baiku.boot.component.core.event.OrmWhen;
import co.baiku.boot.core.orm.service.BaseService;

import java.io.Serializable;

public interface ComponentService<T, D, ID extends Serializable> extends BaseService<T, D, ID>, OrmEventListener<T> {
    /**
     * 创建
     *
     * @param po
     * @return
     */
    T create(T po);

    /**
     * 更新
     *
     * @param po
     * @return
     */
    T update(T po);

    @Override
    default void onCreate(OrmWhen when, T po) {
        this.onCreate(when, po, null);
    }

    @Override
    default void onCreate(OrmWhen when, T po, Exception e) {

    }

    @Override
    default void onUpdate(OrmWhen when, T before, T after) {
        this.onUpdate(when, before, after, null);
    }

    @Override
    default void onUpdate(OrmWhen when, T before, T after, Exception e) {

    }

    @Override
    default void onDelete(OrmWhen when, T po) {
        this.onDelete(when, po, null);
    }

    @Override
    default void onDelete(OrmWhen when, T po, Exception e) {

    }
}
